#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
char from[100], to[100], tmp[100];
char A[6][100], B[6][100];
int len, t;
struct node
{
    char str[100];
    int t;
    node(char str[100] = NULL, int t = 0) : t(t) { strcpy(this->str, str); };
};
queue<node> qu;
int main()
{
    cin >> from >> to;
    while (cin >> A[len] >> B[len])
        len++;
    node now = node(from, 0);
    qu.push(now);
    while (!qu.empty())
    {
        now = qu.front();
        qu.pop();
        strcpy(tmp, now.str);
        t = now.t;
        if (strcmp(tmp, to) == 0 || t > 10)
            break;
        //下面是字符串模板匹配,TODO
    }
    if (t > 10)
        cout << "NO ANSWER!" << endl;
    else
        cout << t << endl;
    return 0;
}